package com.lovo.controller;


import com.lovo.po.User;
import com.lovo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public String login(String userName, String userPwd, HttpSession session){
        User user = userService.login(userName, userPwd);
        if(user!=null){
            session.setAttribute("user",user);
            return "main";
        }else{
            return "error";
        }
    }

    @RequestMapping(value = {"/data","/data/stu","/data/class",
    "/room","/room/roomInfo"})
    public String getUrl(){
        return "url";
    }

    @RequestMapping("/login2")
    @ResponseBody
    public User login2(String userName,String userPwd){
        User user = userService.login(userName, userPwd);
        return user;
    }

    @RequestMapping("/login3")
    @ResponseBody
    public User getUserPermission(Integer userId){
        User user = userService.getUserPermission(userId);
        return user;
    }
}
